/**
 * Created by larry.quns on 2022/1/8.
 */

function meituanBusinessGo() {
    toast("初始化");
    utils.openApp("com.sankuai.meituan");
    sleep(random(500, 700));
    let b = shoppingCart();
    if (!b) {
        antForestGoMTHome();
        if (findNode(descMatch("美团买菜"), true)) {
            sleep(random(300, 600));
            shoppingCart();
        } else {
            toast("未找到美团买菜！");
            loge("未找到美团买菜！");
        }
    }
}
let FindGoHomeCount = 0;
function antForestGoMTHome() {
    if (findNode(descMatch("首页"), true)) {
        sleep(random(300, 700));
        logd("找到美团首页");
        return true;
    }
    FindGoHomeCount = FindGoHomeCount + 1;
    if (FindGoHomeCount >= 10) {
        return false;
    }
    back();
    sleep(random(300, 600))
    antForestGoMTHome();
}

function shoppingCart() {
    if (findNode(id("com.sankuai.meituan:id/img_shopping_cart"), true)) {
        sleep(random(300, 600));
        toast("美团买菜开始自动下单");
        startMeiTuanOrder();
        return true;
    }
    return false;
}
